package com.zkingsoft.actions.admin;

import java.util.Date;

import com.zkingsoft.services.NeedService;

import javax.annotation.Resource;

import com.zkingsoft.actions.common.BaseController;

import org.springframework.stereotype.Controller;

import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.plugin.util.WebUtil;

import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.model.Need;

import org.springframework.web.bind.annotation.RequestMapping;

import com.zkingsoft.anotations.RemoveRequestToken;
import com.zkingsoft.anotations.SaveRequestToken;

/**
 * 
 * @description 需求Controller
 * @author chen
 * @date 2016年12月22日
 */
@Controller
@RequestMapping(value = "admin/need")
public class NeedController extends BaseController{

	@Resource
	private NeedService currentService;
	
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(Need need, PaginationVO pageVo) {
			return showList(currentService, need, pageVo);
	}
   	
	/**
	 * 新增或者修改方法
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(Need need) {
		if (need.getId() != null) {
			return modify(currentService, need, "需求");
		} else{
			need.setCreateTime(new Date());
			need.setCreatePerson(getMe().getId());
			return add(currentService, need, "需求");
		}
	}
	
   	/**
	 * 进入修改界面或新增页面
	 */   
	@SaveRequestToken
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id,Long projId) {
		Need need;
		if (id != null) {
			need = currentService.findById(id);
			WebUtil.getRequest().setAttribute("obj", need);
		}
		WebUtil.getRequest().setAttribute("projId", projId);
		return "admin/need-form";
	}
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
	return remove(currentService, keys);
	}
 	/**
 	 * 进入需求页面
 	 */
 	@RequestMapping(value = "/enter")
	public String enter(Long projId,String projName) {
 		WebUtil.getRequest().setAttribute("projId", projId);
		WebUtil.getRequest().setAttribute("projName", projName);
		return "admin/need-list";
	}
 	
 	
	/**
	 * 进入查看界面
	 */   
   	@RequestMapping(value = "/lookForm")
	public String lookForm(Long id,Long projId) {
		Need need;
		if (id != null) {
			need = currentService.findById(id);
			WebUtil.getRequest().setAttribute("obj", need);
		}
		WebUtil.getRequest().setAttribute("projId", projId);
		return "admin/need-look";
	}

  
}